<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>弹出层</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #button{
          display: flex;
          justify-content: center;
          margin-top: 10px;
        }
        #box{
            width: 500px;
            height: 200px;
            border: 4px solid #FF9900;
            margin:100px auto;
            display: none;
            z-index: 5;
            position: relative;
        }
        .box1{
            width: 500px;
            height: 30px;
            background-color: #FFCC00;
        }
        span{
            width: 15px;
            height: 15px;
            text-align: center;
            line-height: 15px;
            font-size: 12px;
            color: #FF9900;
            font-weight: bold;
            float: right;
            margin-top: 4px;
            margin-right: 10px;
            cursor: pointer;
            border: 1px solid #FF9900;
            background-color: #fff;
        }
        .box2{
            width: 500px;
            height: 166px;
            margin-top: 4px;
            background-color: #fff;
        }
        #yhj{
            width: 100%;
            height: 100%;
            background-color: rgba(180, 179, 179,0.6);
            z-index: 2;
            position: fixed;
            top: 0;
            left: 0;
            display: none;
            
        }
    </style>
</head>
<body>
    <div id="button">
        <button onclick="btn()">弹出层</button>
    </div>
    
    <div id="yhj"></div>
    
    <div id="box">
        <div class="box1"><span id="span">X</span></div>
        <div class="box2"></div>
    </div>

    <script>
        // var btn = document.getElementsByTagName('button')
        var yhj = document.getElementById('yhj')
        var box = document.getElementById('box')
        var span = document.getElementById('span')
        function btn(){
            // alert(2)
            box.style.display = 'block'
            yhj.style.display = 'block'
            // document.body.style.backgroundColor = 'gray'
        }

        span.onclick = function(){
            console.log(2);
            box.style.display = 'none'
            yhj.style.display = 'none'
        }

    </script>
</body>
</html>